/**
  * @FileName: ArrayListAdapter.java
  * @Package:com.bdtop.dbl.ui.adapters
  * @Description: TODO
  * @author: MingjunLi
  * @date:2014-9-15
  * @version V1.0
  */
package com.bdtop.dbl.ui.adapters;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

/**
 * @ClassName: ArrayListAdapter
 * @Description: TODO
 * @author: MingjunLi
 * @date:2014-9-15
 */
public abstract class ArrayListAdapter<T> extends BaseAdapter {
    
    protected List<T> mList;
    protected Activity mContext;
    protected ListView mListView;
    
    public ArrayListAdapter(Activity context){
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList == null ? null : mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public abstract View getView(int position, View convertView, ViewGroup parent);
    
    public void setList(List<T> list){
        this.mList = list;
        notifyDataSetChanged();
    }
    
    public List<T> getList(){
        return mList;
    }
    
    public void setList(T[] list){
        List<T> arrayList = new ArrayList<T>(list.length);  
        for (T t : list) {  
            arrayList.add(t);  
        }  
        setList(arrayList);
    }
    
    public ListView getListView(){
        return mListView;
    }
    
    public void setListView(ListView listView){
        mListView = listView;
    }

}
